<!--
 * @Author: Liz.Zheng
 * @Date: 2021-10-11 09:58:52
 * @LastEditTime: 2023-02-17 19:56:52
 * @LastEditors: 郑亚莉 zhengyali@shequ.life
 * @Description: 子应用载体路由
 * @Motto: Write the code. Change the world.
-->

<template>
  <div id="appRoute"></div>
</template>

<script>
import {
  defineComponent,
  onBeforeUnmount,
  onMounted,
  onUnmounted,
  reactive,
  watch,
} from "vue";
import store from "../../store";
import { useRoute } from "vue-router";
import utils from "../../common/utils/utils";
// import { loadQKApp } from "../../micro_apps";

export default defineComponent({
  name: "appRoute",
  setup() {
    const $route = useRoute();

    const loadApp = () => {
      const appInfo = $route.params?.afterApps?.split("/");
      const appName = appInfo && appInfo[0];
      if (appName) {
        appName != store.getters.currentAppName &&
          store.dispatch("SetCurrentAppName", appName);
        // loadQKApp({
        //   appName,
        // });
      }
    };

    onMounted(() => {
      loadApp();
    });

    // onUnmounted(() => {
    //   store.dispatch("ClearLoadedApp");
    // });

    watch(
      () => $route.params.afterApps,
      (val) => {
        if (val) {
          loadApp();
        }
      }
    );
  },
});
</script>
